<template>
  <div>
     <div class="topbig">
      <p class="cha">&emsp;&emsp;查询</p>
      <div class="sou">
        &emsp;&emsp;&emsp;&emsp;搜索&emsp;<el-input v-model="input" placeholder="输入菜品名称进行搜索" class="shuru" @blur="mohusousuo()"></el-input>
       </div>
    </div>
    <div class="main">
      <p class="caipin">&emsp;&emsp;热卖菜品</p>
     <!-- <el-button type="primary" @click="fun()">新增菜品</el-button>&emsp;&emsp; -->
    </div>


    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="xuhao" label="序号">
      </el-table-column>
      <el-table-column prop="foodName" label="菜品名称"> </el-table-column>
      <el-table-column prop="foodId" label="菜品编号" >
      </el-table-column>
      <el-table-column prop="foodMoney" label="价格">
      </el-table-column>
       <el-table-column prop="foodStatus" label="状态">
      </el-table-column>
      <el-table-column prop="foodSale" label="月销量"> </el-table-column>
      <el-table-column prop="foodNum" label="数量" >
      </el-table-column>
      <el-table-column prop="foodDiscoun" label="折扣">
 
      </el-table-column>
       <el-table-column prop="province" label="操作"  class="caozuo">
        <button @click="tingshou()">{{zanshou}}</button>&emsp;
         <button @click="xiugaizhekou()">修改折扣</button>
      </el-table-column>
    </el-table>

    <div id="xiugaizhekou" v-show="bool">
          <div class="zhekoutop">修改</div>
          <div class="zhekoucenter">
            修改折扣：<input type="text" v-model="zhekou" />
          </div>

          <div class="zhekoubottom">
            <button @click="zhekouqueding()">确定</button>
            <button @click="zhekouquxiao()">取消</button>
          </div>
        </div>

     <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5,10]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

   
  </div>
</template>

<script>
import {findAllFoodByLimit,findlikelimit} from "@/apis/ningsh/ningsh.js";
export default {
  data() {
    return {
      total:0,
      pageSize:5,
      input: '',
      caipingzhekou:'',
      bool:false,
      zhekou:'',
      select:'',
     currentPage: 1,
      tableData: [
        {},
      ],
      tableDatab:[{}],
      xuhao:'',
    //  tingshou:[],
     zanshou:'暂停出售',
    };

  },
  computed:{
      foodId(){
        return this.tableDatab.map(item=>item.foodId)
      }
  },
 methods:{
  render() {
      findAllFoodByLimit().then((ok) => {
        console.log(ok);
        this.tableDatab = ok.data.data.records;
          this.tableData = ok.data.data.records.slice((this.currentPage-1)*this.pageSize,this.currentPage*this.pageSize)
          this.total=this.tableDatab.length
        let [caiping] = this.tableData;
        this.caipingzhekou = caiping.foodDiscoun;
       
      });

    },
    mohusousuo(){
      //input模糊查询
        findlikelimit(this.input).then((ok)=>{
          console.log(ok);
          this.tableData=ok.data.data.records
          
        })
    },
    xiugaizhekou(){
      this.bool=true
    },
     zhekouqueding() {
      //修改折扣
     
      this.bool = false;
    },
    zhekouquxiao() {
      this.bool = false;
    },
     handleSizeChange(val) {
      this.pageSize=val
      this.render()
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage=val
      this.render()

    },
  tingshou(){
      
        // haltArrfoods(this.foodId).then((ok)=>{
        //   console.log(ok);
        // })  
       this.zanshou='已停售'   
  }
 },
 mounted() {
    this.render();
  },
 
  
};
</script>

<style scoped>
.topbig {
  width: 100%;
  height: 145px;
  border: 1px solid #ccc;
}
.cha {
  display: flex;
  align-items: center;
  height: 45%;
  background-color: #ccc;
}
.sou {
  font-size: 10px;
  height: 55%;
  display: flex;
  align-items: center;
}
.shuru{
  width: 300px;
}
.main {
  margin-top: 10px;
  margin-bottom: 10px;
  background-color: #ccc;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.caipin {
  width: 100%;
  display: flex;
  align-items: center;
  height: 60px;
}
#xiugaizhekou {
  width: 200px;
  height: 150px;
  background-color: #eeecec;
  position: fixed;
  /* bottom: 100px;
  left: 560px; */
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
  border: 2px solid blue;
}
.zhekoutop {
  text-align: center;
  margin-top: 10px;
  margin-bottom: 10px;
}
.zhekoubottom {
  display: flex;
  margin-top: 30px;
  justify-content: space-evenly;
  align-items: center;
}
.caozuo{
  display: flex;
}
</style>